package net.hn.hnms.biz.plan.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import net.hn.hnms.biz.plan.domain.DimDrivageFace;
import net.hn.hnms.biz.plan.domain.DimMiningFace;
import net.hn.hnms.biz.plan.domain.DimShift;
import net.hn.hnms.biz.plan.domain.ExecutionFootageOutput;
import net.hn.hnms.biz.plan.enums.WorkFaceType;
import net.hn.hnms.biz.plan.mapper.*;
import net.hn.hnms.biz.plan.service.*;
import net.hn.hnms.biz.plan.vo.*;
import net.hn.hnms.sys.common.core.constant.Constants;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.exception.HuaNengException;
import net.hn.hnms.sys.common.core.utils.DateUtils;
import net.hn.hnms.sys.common.core.utils.StringUtils;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.biz.plan.request.CooperativeMiningFacReq;
import net.hn.hnms.biz.plan.request.DimDrivageFaceReq;
import net.hn.hnms.biz.plan.request.DimMiningFaceReq;
import net.hn.hnms.biz.plan.request.ExecutionFootageOutputReq;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

import static org.apache.poi.ss.usermodel.BorderStyle.THIN;
import static org.apache.poi.ss.usermodel.HorizontalAlignment.CENTER;

/**
 * @author zhaoyang
 * 进尺产量执行服务层实现
 * @date 2022-08-01
 */

@Service
@Slf4j
@DS("master")
public class ExecutionFootageOutputServiceImpl extends BaseService<ExecutionFootageOutput, ExecutionFootageOutputVO> implements IExecutionFootageOutputService {

    @Autowired
    private ExecutionFootageOutputMapper executionFootageOutputMapper;
    @Autowired
    private DimDrivageFaceMapper dimDrivageFaceMapper;
    @Autowired
    private DimMiningFaceMapper dimMiningFaceMapper;
    @Autowired
    private DimShiftMapper dimShiftMapper;

    @Autowired
    private IDimMiningFaceService iDimMiningFaceService;
    @Autowired
    private IDimDrivageFaceService iDimDrivageFaceService;
    @Autowired
    private CooperativeMiningFacService cooperativeMiningFacService;
    @Autowired
    private PlanMiningMapper planMiningMapper;
    @Autowired
    private IStatisticService iStatisticService;
    @Autowired
    private IExecutionWashingService iExecutionWashingService;

    /**
     * @param executionFootageOutput
     * @param pageQuery       查询进尺产量执行列表
     */
    @Override
    public ResponsePage<ExecutionFootageOutputVO> selectPageList(ExecutionFootageOutputReq executionFootageOutput, PageQuery pageQuery) {

        Page<ExecutionFootageOutput> page = executionFootageOutputMapper.selectPage(pageQuery.build(), buildQuery(executionFootageOutput).orderByDesc(ExecutionFootageOutput::getExecutionDate)
                .orderByDesc(ExecutionFootageOutput::getCreateTime));
        List<ExecutionFootageOutputVO> list = page.getRecords().stream().map(o -> convertWithUser(o, ExecutionFootageOutputVO.class)).collect(Collectors.toList());


        if (CollUtil.isNotEmpty(list)) {
                Set<String> shiftIds = list.stream().map(ExecutionFootageOutputVO::getShiftId).collect(Collectors.toSet());
            Set<String> drivageFaceIds = list.stream().filter(o->o.getWorkFaceType().equals(WorkFaceType.DRAVIGE.getCode())).map(ExecutionFootageOutputVO::getWorkFaceId).collect(Collectors.toSet());
            Set<String> miningFaceIds = list.stream().filter(o->o.getWorkFaceType().equals(WorkFaceType.MINING.getCode())).map(ExecutionFootageOutputVO::getWorkFaceId).collect(Collectors.toSet());
            DynamicDataSourceContextHolder.push("slave");
            Map<String, String> shiftMap = dimShiftMapper.selectList(new LambdaQueryWrapper<DimShift>()
                            .in(CollUtil.isNotEmpty(shiftIds), DimShift::getShiftId, shiftIds)
                            .eq(StrUtil.isNotBlank(executionFootageOutput.getMineCode()), DimShift::getMineCode, executionFootageOutput.getMineCode())
                    )
                    .stream().collect(Collectors.toMap(DimShift::getShiftId, DimShift::getShiftName));

            Map<String, String> drivageMap = dimDrivageFaceMapper.selectList(new LambdaQueryWrapper<DimDrivageFace>()
                            .in(CollUtil.isNotEmpty(drivageFaceIds), DimDrivageFace::getDrivageFaceId, drivageFaceIds)
                            .eq(StrUtil.isNotBlank(executionFootageOutput.getMineCode()), DimDrivageFace::getMineCode, executionFootageOutput.getMineCode()))
                    .stream().collect(Collectors.toMap(DimDrivageFace::getDrivageFaceId, DimDrivageFace::getDrivageFaceName));

            Map<String, String> miningMap = dimMiningFaceMapper.selectList(new LambdaQueryWrapper<DimMiningFace>()
                            .in(CollUtil.isNotEmpty(miningFaceIds), DimMiningFace::getMiningFaceId, miningFaceIds)
                            .eq(StrUtil.isNotBlank(executionFootageOutput.getMineCode()), DimMiningFace::getMineCode, executionFootageOutput.getMineCode()))
                    .stream().collect(Collectors.toMap(DimMiningFace::getMiningFaceId, DimMiningFace::getMiningFaceName));

            DynamicDataSourceContextHolder.clear();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (ExecutionFootageOutputVO outputVO : list) {
                outputVO.setShiftName(shiftMap.get(outputVO.getShiftId()));
                outputVO.setWorkFaceName(drivageMap.containsKey(outputVO.getWorkFaceId()) ? drivageMap.get(outputVO.getWorkFaceId()) : miningMap.get(outputVO.getWorkFaceId()));
                Date[] monthDateRange = DateUtils.getDateRange(DateUtil.year(outputVO.getExecutionDate()), outputVO.getExecutionDate().getMonth()+1);
                Date[] yearDateRange = DateUtils.getDateRange(DateUtil.year(outputVO.getExecutionDate()),null);
                if (outputVO.getShiftId().equals("0298c8a9d0639d715a0925f7b1ec2f55")) {
                    executionFootageOutput.setType("1");

                } else if (outputVO.getShiftId().equals("0e0220e4af825d70d0932cc4504cd80d")) {
                    executionFootageOutput.setType("2");

                } else if (outputVO.getShiftId().equals("70b1dacd7bf4db32cd37c1322a290005")) {
                    executionFootageOutput.setType("3");

                }

                Calendar calendar = Calendar.getInstance();
                calendar.setTime(outputVO.getExecutionDate());
                calendar.add(Calendar.DATE,-1);

                executionFootageOutput.setExecutionDateReq(sdf.format(outputVO.getExecutionDate()));
                executionFootageOutput.setMonthBeginDate(sdf.format(monthDateRange[0]));
                executionFootageOutput.setMonthEndDate(sdf.format(calendar.getTime()));
                executionFootageOutput.setYearBeginDate(sdf.format(yearDateRange[0]));
                executionFootageOutput.setYearEndDate(sdf.format(calendar.getTime()));

                executionFootageOutput.setWorkFaceId(outputVO.getWorkFaceId());
                ExecutionFootageOutputVO v= executionFootageOutputMapper.getYearOrMonthFootageOutput(executionFootageOutput);
                outputVO.setMonthOutput(v.getMonthOutput());
                outputVO.setMonthFootage(v.getMonthFootage());
                outputVO.setYearOutput(v.getYearOutput());
                outputVO.setYearFootage(v.getYearFootage());
            }
        }
        return new ResponsePage<>(list, page.getTotal());
    }

    /**
     * 构造查询条件
     * @param req
     * @return LambdaQueryWrapper<ExecutionFootageOutput> 查询条件
     */
    private LambdaQueryWrapper<ExecutionFootageOutput> buildQuery(ExecutionFootageOutputReq req){
        LambdaQueryWrapper<ExecutionFootageOutput> lqw = new LambdaQueryWrapper<ExecutionFootageOutput>()
                .ge(req.getBeginDateTime() != null, ExecutionFootageOutput::getExecutionDate, req.getBeginDateTime())
                .le(req.getEndDateTime() != null, ExecutionFootageOutput::getExecutionDate, req.getEndDateTime())
//                .eq(StrUtil.isNotBlank(req.getMineCode()), ExecutionFootageOutput::getMineCode, req.getMineCode())
                .eq(StrUtil.isNotBlank(req.getShiftId()), ExecutionFootageOutput::getShiftId, req.getShiftId())
                .eq(StrUtil.isNotBlank(req.getWorkFaceType()), ExecutionFootageOutput::getWorkFaceType, req.getWorkFaceType())
                .eq(StrUtil.isNotBlank(req.getWorkFaceId()), ExecutionFootageOutput::getWorkFaceId, req.getWorkFaceId())
                .and(o -> o.eq(req.getMineCode() != null, ExecutionFootageOutput::getMineCode, req.getMineCode())
                                .or()
                                .eq(req.getCompanyCode() != null, ExecutionFootageOutput::getCompanyCode, req.getCompanyCode())
                );



//                .and(o->o.eq(req.getMineCode()!=null, ExecutionFootageOutput::getMineCode, req.getMineCode())
//                        .or()
//                        .eq(req.getCompanyCode()!=null, ExecutionFootageOutput::getCompanyCode, req.getCompanyCode()));


        return lqw;
    }

    /**
     *
     * @param executionFootageOutput
     * 查询带值班人员列表
     */
    @Override
    public List<ExecutionFootageOutputVO> selectList(ExecutionFootageOutputReq executionFootageOutput) {
        List<ExecutionFootageOutput> list = executionFootageOutputMapper.selectList(buildQuery(executionFootageOutput));
        return convert(list, ExecutionFootageOutputVO.class, false);
    }

    @Override
    public List<ExecutionFootageOutputVO> selectListOfExport(ExecutionFootageOutputReq executionFootageOutput) {

        List<ExecutionFootageOutput> list = executionFootageOutputMapper.selectList(buildQuery(executionFootageOutput));
        List<ExecutionFootageOutputVO> convert = convert(list, ExecutionFootageOutputVO.class, false);
        if (CollUtil.isNotEmpty(list)) {
            Set<String> shiftIds = convert.stream().map(ExecutionFootageOutputVO::getShiftId).collect(Collectors.toSet());
            Set<String> drivageFaceIds = convert.stream().filter(o->o.getWorkFaceType().equals(WorkFaceType.DRAVIGE.getCode())).map(ExecutionFootageOutputVO::getWorkFaceId).collect(Collectors.toSet());
            Set<String> miningFaceIds = convert.stream().filter(o->o.getWorkFaceType().equals(WorkFaceType.MINING.getCode())).map(ExecutionFootageOutputVO::getWorkFaceId).collect(Collectors.toSet());
            DynamicDataSourceContextHolder.push("slave");
            Map<String, String> shiftMap = dimShiftMapper.selectList(new LambdaQueryWrapper<DimShift>()
                            .in(CollUtil.isNotEmpty(shiftIds), DimShift::getShiftId, shiftIds)
                            .eq(StrUtil.isNotBlank(executionFootageOutput.getMineCode()), DimShift::getMineCode, executionFootageOutput.getMineCode())
                    )
                    .stream().collect(Collectors.toMap(DimShift::getShiftId, DimShift::getShiftName));

            Map<String, String> drivageMap = dimDrivageFaceMapper.selectList(new LambdaQueryWrapper<DimDrivageFace>()
                            .in(CollUtil.isNotEmpty(drivageFaceIds), DimDrivageFace::getDrivageFaceId, drivageFaceIds)
                            .eq(StrUtil.isNotBlank(executionFootageOutput.getMineCode()), DimDrivageFace::getMineCode, executionFootageOutput.getMineCode()))
                    .stream().collect(Collectors.toMap(DimDrivageFace::getDrivageFaceId, DimDrivageFace::getDrivageFaceName));

            Map<String, String> miningMap = dimMiningFaceMapper.selectList(new LambdaQueryWrapper<DimMiningFace>()
                            .in(CollUtil.isNotEmpty(miningFaceIds), DimMiningFace::getMiningFaceId, miningFaceIds)
                            .eq(StrUtil.isNotBlank(executionFootageOutput.getMineCode()), DimMiningFace::getMineCode, executionFootageOutput.getMineCode()))
                    .stream().collect(Collectors.toMap(DimMiningFace::getMiningFaceId, DimMiningFace::getMiningFaceName));

            DynamicDataSourceContextHolder.clear();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (ExecutionFootageOutputVO outputVO : convert) {
                outputVO.setShiftName(shiftMap.get(outputVO.getShiftId()));
                outputVO.setWorkFaceName(drivageMap.containsKey(outputVO.getWorkFaceId()) ? drivageMap.get(outputVO.getWorkFaceId()) : miningMap.get(outputVO.getWorkFaceId()));
                Date[] monthDateRange = DateUtils.getDateRange(DateUtil.year(outputVO.getExecutionDate()), outputVO.getExecutionDate().getMonth()+1);
                Date[] yearDateRange = DateUtils.getDateRange(DateUtil.year(outputVO.getExecutionDate()),null);
                if (outputVO.getShiftId().equals("0298c8a9d0639d715a0925f7b1ec2f55")) {
                    executionFootageOutput.setType("1");

                } else if (outputVO.getShiftId().equals("0e0220e4af825d70d0932cc4504cd80d")) {
                    executionFootageOutput.setType("2");

                } else if (outputVO.getShiftId().equals("70b1dacd7bf4db32cd37c1322a290005")) {
                    executionFootageOutput.setType("3");

                }

                Calendar calendar = Calendar.getInstance();
                calendar.setTime(outputVO.getExecutionDate());
                calendar.add(Calendar.DATE,-1);

                executionFootageOutput.setExecutionDateReq(sdf.format(outputVO.getExecutionDate()));
                executionFootageOutput.setMonthBeginDate(sdf.format(monthDateRange[0]));
                executionFootageOutput.setMonthEndDate(sdf.format(calendar.getTime()));
                executionFootageOutput.setYearBeginDate(sdf.format(yearDateRange[0]));
                executionFootageOutput.setYearEndDate(sdf.format(calendar.getTime()));

                executionFootageOutput.setWorkFaceId(outputVO.getWorkFaceId());
                ExecutionFootageOutputVO v= executionFootageOutputMapper.getYearOrMonthFootageOutput(executionFootageOutput);
                outputVO.setMonthOutput(v.getMonthOutput());
                outputVO.setMonthFootage(v.getMonthFootage());
                outputVO.setYearOutput(v.getYearOutput());
                outputVO.setYearFootage(v.getYearFootage());
            }
        }
        return convert;
    }

    /**
     * @param executionFootageOutput 新增进尺产量
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insert(ExecutionFootageOutputReq executionFootageOutput) {
//        QueryWrapper<ExecutionFootageOutput> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("development_plan_code", executionFootageOutput.getExecutionFootageOutputCode());
//        if (executionFootageOutputMapper.selectCount(queryWrapper) > 0) {
//            throw new HuaNengException(Constants.FAIL, "已存在相同的计划编号");
//        }
        ExecutionFootageOutput insertObj = new ExecutionFootageOutput();
        BeanUtil.copyProperties(executionFootageOutput, insertObj);
        return executionFootageOutputMapper.insert(insertObj);
    }

    /**
     * @param idList 批量删除 id集合
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(List<String> idList) {
        executionFootageOutputMapper.deleteBatchIds(idList);
    }

    /**
     * @param executionFootageOutput 单个修改 按照主键修改信息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateById(ExecutionFootageOutputReq executionFootageOutput) {
        if (StrUtil.isBlank(executionFootageOutput.getFootageExecutionId())) {
            throw new HuaNengException(Constants.FAIL, "id不能为空");
        }
        ExecutionFootageOutput updateObj = new ExecutionFootageOutput();
        BeanUtil.copyProperties(executionFootageOutput, updateObj);
        int updateCount = executionFootageOutputMapper.updateById(updateObj);
        if (updateCount == 0) {
            throw new HuaNengException(Constants.FAIL, "数据不存在");
        }
    }

    /**
     * @param id 按主键id查询详情
     */
    @Override
    public ExecutionFootageOutputVO selectDetailById(String id) {
        ExecutionFootageOutput executionFootageOutput = executionFootageOutputMapper.selectById(id);
        if (executionFootageOutput == null) {
            throw new HuaNengException(Constants.FAIL, "数据不存在");
        }
        return convertWithUser(executionFootageOutput, ExecutionFootageOutputVO.class);
    }

    public ExecutionFootageOutputVO selectFootageAndDevelop(String id){
        ExecutionFootageOutput executionFootageOutput = executionFootageOutputMapper.selectFootageAndDevelop(id);
        if (executionFootageOutput == null) {
            throw new HuaNengException(Constants.FAIL, "数据不存在");
        }
//          return convert(executionFootageOutput, ExecutionFootageOutputVO.class, false);
        return convertWithUser(executionFootageOutput, ExecutionFootageOutputVO.class);
    }

    public List<ExecutionFootageOutputVO> detailFootageAndDevelopByData(String id,String date){
        List<ExecutionFootageOutput> list = executionFootageOutputMapper.detailFootageAndDevelopByData(id,date);
        return convert(list, ExecutionFootageOutputVO.class, false);
    }

    @Override
    public List<ExecutionFootageOutputVO> selectLastSevenDaysDetailFD(String id) {
        List<ExecutionFootageOutput> list = executionFootageOutputMapper.selectLastSevenDaysDetailFD(id);
        return convert(list, ExecutionFootageOutputVO.class, false);
    }

    @Override
    public MiningFaceScheduleVo getMiningFaceSchedule(String name) {
        DimMiningFaceVO dimMiningFaceVO=iDimMiningFaceService.getWorkingFaceId(name);

        MiningFaceScheduleVo v=null;

        if (dimMiningFaceVO!=null&&StrUtil.isNotBlank(dimMiningFaceVO.getMiningFaceId())) {
            v=executionFootageOutputMapper.getMiningFaceSchedule(dimMiningFaceVO.getMiningFaceId());
            if(v!=null){
                v.setMiningRoadwayLength(dimMiningFaceVO.getMiningFaceLength());
                v.setPercentageComplete(v.getDoneMiningRoadwayLength()==null||v.getMiningRoadwayLength()==null?"0":v.getDoneMiningRoadwayLength().divide(v.getMiningRoadwayLength(),BigDecimal.ROUND_CEILING).multiply(BigDecimal.valueOf(100)).intValue()+"%");
            }
        }

        return v;
    }

    @Override
    public   List<ExecutionFootageOutputVO>  getProductionStatisticsDrivage(String beginDate, String mineCode) {

        if(StringUtils.isBlank(beginDate)){
            // 创建Calendar对象
            Calendar calendar = Calendar.getInstance();
            // 将当前时间减去一天
            calendar.add(Calendar.DATE, -1);
            // 创建一个日期格式化对象
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            // 格式化新的时间
            beginDate = format.format(calendar.getTime());
        }

        System.out.println("进入方法");
        ExecutionFootageOutputVO  executionFootageOutputVO = new ExecutionFootageOutputVO();
        List<ExecutionFootageOutputVO> executionFootageOutputVOList = new ArrayList<>();

        DimMiningFaceReq dimMiningFaceReq = new DimMiningFaceReq();
        DimDrivageFaceReq dimDrivageFaceReq = new DimDrivageFaceReq();
        dimMiningFaceReq.setMineCode(mineCode);
        dimMiningFaceReq.setStatus("0");

        dimDrivageFaceReq.setStatus("0");
        dimDrivageFaceReq.setMineCode(mineCode);
        List<DimDrivageFaceVO> drivageFaceVOS = iDimDrivageFaceService.selectList(dimDrivageFaceReq);//掘进面
        ExecutionWashingVO washing = iExecutionWashingService.selectByDate(mineCode,beginDate);
        SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
        SimpleDateFormat yearFormat = new SimpleDateFormat("YYYY");
        LocalDate ymd = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        int month = ymd.getMonthValue();
        int years = ymd.getYear();
//        Integer month = Integer.parseInt(monthFormat.format(beginDate));
//        Integer years = Integer.parseInt(yearFormat.format(beginDate));
        int t = 0;
        BigDecimal morningTotal = BigDecimal.ZERO;
        BigDecimal afternoonTotal = BigDecimal.ZERO;
        BigDecimal nightTotal = BigDecimal.ZERO;
        for (DimDrivageFaceVO dimMiningFaceVO : drivageFaceVOS){

            ExecutionFootageOutputVO leiji = executionFootageOutputMapper.selectPlanOutPutByFaceId(dimMiningFaceVO.getDrivageFaceId(), beginDate, null);
            BigDecimal leijifootage = new BigDecimal("0");
            if(leiji==null){
                leijifootage.add(new BigDecimal("0"));
            }else{
                leijifootage = leijifootage.add(leiji.getFootage());
            }

            executionFootageOutputVO.setDistrict("掘进二队");
            executionFootageOutputVO.setWorkFaceName(dimMiningFaceVO.getDrivageFaceName());//掘进工作面名称
            executionFootageOutputVO.setFaceLength(dimMiningFaceVO.getDrivageFaceLength());//掘进工作面长度
           executionFootageOutputVO.setYearFootage(leijifootage);;//累计
           executionFootageOutputVO.setResidue(dimMiningFaceVO.getDrivageFaceLength().subtract(leijifootage));  //剩余


            //根据工作面查询三班进尺
            BigDecimal todayleijifootage = new BigDecimal("0");
            List<ExecutionFootageOutputVO> outputVOS = detailFootageAndDevelopByData(dimMiningFaceVO.getDrivageFaceId(),beginDate);

            for (ExecutionFootageOutputVO footageOutputVO : outputVOS) {
                t++;
                todayleijifootage = todayleijifootage.add(footageOutputVO.getFootage());

                BigDecimal footage = footageOutputVO.getFootage();

                if (t == 1) {
                    executionFootageOutputVO.setMorning(footage);
                    morningTotal = morningTotal.add(footage);
                } else if (t == 2) {
                    executionFootageOutputVO.setAfternoon(footage);
                    afternoonTotal = afternoonTotal.add(footage);
                } else {
                    executionFootageOutputVO.setNight(footage);
                    nightTotal = nightTotal.add(footage);
                }
            }
            executionFootageOutputVO.setMorningTotal( morningTotal);
            executionFootageOutputVO.setAfternoonTotal(afternoonTotal);
            executionFootageOutputVO.setNightTotal(nightTotal);

            executionFootageOutputVO.setDayFootage(todayleijifootage);//日推进
            Date[] dateRange = DateUtils.getDateRange(null, month);
            Date[] yearsdateRange = DateUtils.getDateRange(years, null);
            String s = DateUtils.parseDateToStr("yyyy-MM-dd", dateRange[0]);
            String y = DateUtils.parseDateToStr("yyyy-MM-dd", yearsdateRange[0]);

            //查询月累计进尺
            ExecutionFootageOutputVO footageOutputVO = executionFootageOutputMapper.selectPlanOutPutByFaceIdAndDate(dimMiningFaceVO.getDrivageFaceId(), s, beginDate);
            executionFootageOutputVO.setMonthFootage(footageOutputVO.getFootage());//月累计
            executionFootageOutputVO.setYearFootage(leijifootage);//累计量

            ExecutionFootageOutputVO yuefootage = executionFootageOutputMapper.selectPlanOutPutByFaceIdAndDate(null, s, beginDate);
            ExecutionFootageOutputVO nianfootage = executionFootageOutputMapper.selectPlanOutPutByFaceIdAndDate(null, y, beginDate);
            executionFootageOutputVO.setMonthOutput(yuefootage==null?new BigDecimal(""):yuefootage.getFootage());//月合计
            executionFootageOutputVO.setYearOutput(nianfootage==null?new BigDecimal(""):nianfootage.getFootage());//年合计


            List<ExecutionFootageOutputVO> rioutput = detailFootageAndDevelopByData(null,beginDate);
            BigDecimal totalFootage = rioutput.stream()
                    .map(ExecutionFootageOutputVO::getFootage)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            executionFootageOutputVO.setDayOutput(totalFootage==null?new BigDecimal(""):totalFootage);//日合计

            executionFootageOutputVOList.add(executionFootageOutputVO);
        }

        return executionFootageOutputVOList;
    }

    @Override
    public List<ExecutionFootageOutputVO> getProductionStatisticsMining(String beginDate, String mineCode) {

        if(StringUtils.isBlank(beginDate)){
            // 创建Calendar对象
            Calendar calendar = Calendar.getInstance();
            // 将当前时间减去一天
            calendar.add(Calendar.DATE, -1);
            // 创建一个日期格式化对象
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            // 格式化新的时间
            beginDate = format.format(calendar.getTime());
        }

        System.out.println("进入方法");
        ExecutionFootageOutputVO  executionFootageOutputVO = new ExecutionFootageOutputVO();
        List<ExecutionFootageOutputVO> executionFootageOutputVOList = new ArrayList<>();

        DimMiningFaceReq dimMiningFaceReq = new DimMiningFaceReq();
        DimDrivageFaceReq dimDrivageFaceReq = new DimDrivageFaceReq();
        dimMiningFaceReq.setMineCode(mineCode);
        dimMiningFaceReq.setStatus("0");

        dimDrivageFaceReq.setStatus("0");
        dimDrivageFaceReq.setMineCode(mineCode);
        List<DimMiningFaceVO> dimMiningFaceVOS = iDimMiningFaceService.selectList(dimMiningFaceReq);//回采面
        ExecutionWashingVO washing = iExecutionWashingService.selectByDate(mineCode,beginDate);
        SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
        SimpleDateFormat yearFormat = new SimpleDateFormat("YYYY");

        ProduceStasticVO produceStasticVO = iStatisticService.produceForBigScreen(beginDate, mineCode);
        if (dimMiningFaceVOS.size()>0){
            executionFootageOutputVO.setMorning(produceStasticVO.getProduceDay());
            executionFootageOutputVO.setAfternoon(produceStasticVO.getProduceMonth());
            executionFootageOutputVO.setNight(produceStasticVO.getProduceYear());
        }
        executionFootageOutputVO.setMorningTotal(washing==null?new BigDecimal("0"):washing.getTotalShaleAmount());//矸石
        executionFootageOutputVO.setAfternoonTotal(washing==null?new BigDecimal("0"):washing.getTotalWashingAmount());//洗选量
        executionFootageOutputVO.setNightTotal(washing==null?new BigDecimal("0"):washing.getTotalCoalAmount());//总商品煤量
        for (DimMiningFaceVO dimMiningFaceVO : dimMiningFaceVOS) {
            //根据工作面id获取进尺，获取当日进尺，获取月计划
            CooperativeMiningFacReq cooperativeMiningFacReq =new CooperativeMiningFacReq();
            cooperativeMiningFacReq.setMineCode(dimMiningFaceVO.getMineCode());
            cooperativeMiningFacReq.setId(dimMiningFaceVO.getMiningFaceId());
            log.info(cooperativeMiningFacReq.getId()+"回采工作面ID");
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            // 将 String 转换为 LocalDate
            LocalDate date = LocalDate.parse(beginDate, formatter);
            cooperativeMiningFacReq.setDate(date);

            CooperativeMiningFacVo cooperativeMiningFacVo = cooperativeMiningFacService.selectData(cooperativeMiningFacReq);

            BigDecimal months = planMiningMapper.planMonth(dimMiningFaceVO.getMiningFaceId(), dimMiningFaceVO.getMineCode(),beginDate);
            BigDecimal year = planMiningMapper.planYear(dimMiningFaceVO.getMiningFaceId(), dimMiningFaceVO.getMineCode(),beginDate);
            executionFootageOutputVO.setDistrict("综采二队");
            executionFootageOutputVO.setWorkFaceName(dimMiningFaceVO.getMiningFaceName());
            executionFootageOutputVO.setTotalFootage(dimMiningFaceVO.getMiningFaceLength());
            //已采长度
            executionFootageOutputVO.setFaceLength(cooperativeMiningFacVo.getCurrentlyMineds());
            //剩余长度
            executionFootageOutputVO.setResidue(cooperativeMiningFacVo.getOverslength());
            //推采进度
            executionFootageOutputVO.setDayFootage(cooperativeMiningFacVo.getNowFootage());
            //月计划
            executionFootageOutputVO.setMonthOutput(months);
            //年计划
            executionFootageOutputVO.setYearOutput(year);
            executionFootageOutputVOList.add(executionFootageOutputVO);

        }


        return executionFootageOutputVOList;
    }

    private void createTitle(HSSFWorkbook wb, HSSFRow titleRow, String title) {
        titleRow.setHeight((short) 600);
        HSSFCell cell = titleRow.createCell(0);

        HSSFRichTextString h = new HSSFRichTextString(title);
        // 字体样式
        HSSFFont font = wb.createFont();
//        font.setColor((short) 8);
        font.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
        font.setFontHeightInPoints((short) 18);
        font.setBold(true);
        h.applyFont(font);
        cell.setCellValue(h);
        cell.setCellStyle(getCellDefaultStyle(wb, HSSFColor.HSSFColorPredefined.WHITE.getIndex()));
    }
    private HSSFCellStyle getCellDefaultStyle(HSSFWorkbook wb, short color) {
        // 设置单元格样式
        HSSFCellStyle cellstyle = wb.createCellStyle();
        cellstyle.setAlignment(CENTER);// 设置水平对齐方式
        cellstyle.setVerticalAlignment(VerticalAlignment.CENTER);// 设置垂直对齐方式
        cellstyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
//        cellstyle.set
        cellstyle.setFillPattern(FillPatternType.forInt(1));
        cellstyle.setBorderBottom(THIN);
        cellstyle.setBorderLeft(THIN);
        cellstyle.setBorderRight(THIN);
        cellstyle.setBorderTop(THIN);
        cellstyle.setAlignment(CENTER);

        cellstyle.setWrapText(true);
        return cellstyle;
    }
    private void createCell(HSSFWorkbook wb, HSSFRow row, int col, String val, HSSFColor.HSSFColorPredefined color, String ver) {
        HSSFCell cell = row.createCell(col);
        cell.setCellValue(val);

        HSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER); // 设置水平对齐方式
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 设置垂直对齐方式
        cellStyle.setWrapText(true); // 设置自动换行

        // 设置边框
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setBorderTop(BorderStyle.THIN);

        // 字体样式
        HSSFFont font = wb.createFont();
        if (ver.equals("1")) {
            // 设置文字方向为竖直
            cellStyle.setRotation((short) 255);
            cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            cellStyle.setIndention((short) 1);

            // 设置字体颜色为红色
            font.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
            font.setBold(true);
        } else if (ver.equals("2")) {
            // 字体加粗
            font.setBold(true);
        }
        cellStyle.setFont(font);

        // 应用样式到单元格
        cell.setCellStyle(cellStyle);

        // 自适应行高
        int cellHeight = val.length() * 200; // 根据字符个数设置行高
        row.setHeight((short) 600);
    }




    @Override
    public void exportProductionStatisticsData(HttpServletResponse response, String beginDate,String mineCode) {

        if(StringUtils.isBlank(beginDate)){
            // 创建Calendar对象
            Calendar calendar = Calendar.getInstance();
            // 将当前时间减去一天
            calendar.add(Calendar.DATE, -1);
            // 创建一个日期格式化对象
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            // 格式化新的时间
            beginDate = format.format(calendar.getTime());
        }

        System.out.println("进入方法");

        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet();
        sheet.setVerticallyCenter(true);
//        sheet.setColumnWidth(0,256+184);
        DimMiningFaceReq dimMiningFaceReq = new DimMiningFaceReq();
        DimDrivageFaceReq dimDrivageFaceReq = new DimDrivageFaceReq();
        dimMiningFaceReq.setMineCode(mineCode);
        dimMiningFaceReq.setStatus("0");

        dimDrivageFaceReq.setStatus("0");
        dimDrivageFaceReq.setMineCode(mineCode);
        List<DimMiningFaceVO> dimMiningFaceVOS = iDimMiningFaceService.selectList(dimMiningFaceReq);//回采面
        List<DimDrivageFaceVO> drivageFaceVOS = iDimDrivageFaceService.selectList(dimDrivageFaceReq);//掘进面
        ExecutionWashingVO washing = iExecutionWashingService.selectByDate(mineCode,beginDate);


        wb.setSheetName(0,"砚北煤矿安全生产信息统计表");
        HSSFRow titleRow = sheet.createRow(0);
        HSSFRow head = sheet.createRow(1);
        HSSFRow head2 = sheet.createRow(2);
        HSSFRow head3 = sheet.createRow(3);
        HSSFRow head4 = sheet.createRow(4);
        HSSFRow headf5 = sheet.createRow(3+dimMiningFaceVOS.size()+1);
        HSSFRow headf4 = sheet.createRow(3+dimMiningFaceVOS.size()+2);
        HSSFRow headf3 = sheet.createRow(3+dimMiningFaceVOS.size()+3);
        HSSFRow headf2 = sheet.createRow(3+dimMiningFaceVOS.size()+4);
        HSSFRow headf1 = sheet.createRow(3+dimMiningFaceVOS.size()+5);
        HSSFRow headz1 = sheet.createRow(3+dimMiningFaceVOS.size()+5+1);
        HSSFRow headz2 = sheet.createRow(3+dimMiningFaceVOS.size()+5+2);
        HSSFRow headLast = sheet.createRow(1+3+ dimMiningFaceVOS.size()+5+2+drivageFaceVOS.size());
        HSSFRow headLast1 = sheet.createRow(2+3+ dimMiningFaceVOS.size()+5+2+drivageFaceVOS.size());
        createCell(wb,headf4,7,washing==null?"":washing.getTotalShaleAmount()+"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"3");//矸石
        createCell(wb,headf2,7,washing==null?"":washing.getTotalWashingAmount()+"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"3");//洗选量
        createCell(wb,headf1,7,washing==null?"":washing.getTotalCoalAmount()+"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"3");//总商品煤量

        HSSFRow bodyRow = null;
        int rows = 1;
        int i = 0;
        int m =  3+ dimMiningFaceVOS.size()+5+2+1;
        SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
        SimpleDateFormat yearFormat = new SimpleDateFormat("YYYY");
        LocalDate ymd = LocalDate.parse(beginDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        int month = ymd.getMonthValue();
        int years = ymd.getYear();
//        Integer month = Integer.parseInt(monthFormat.format(beginDate));
//        Integer years = Integer.parseInt(yearFormat.format(beginDate));
        int t = 0;
        int m1 = 0;
        BigDecimal morningTotal = BigDecimal.ZERO;
        BigDecimal afternoonTotal = BigDecimal.ZERO;
        BigDecimal nightTotal = BigDecimal.ZERO;
        for (DimDrivageFaceVO dimMiningFaceVO : drivageFaceVOS){

            ExecutionFootageOutputVO leiji = executionFootageOutputMapper.selectPlanOutPutByFaceId(dimMiningFaceVO.getDrivageFaceId(), beginDate, null);
            BigDecimal leijifootage = new BigDecimal("0");
            if(leiji==null){
                leijifootage.add(new BigDecimal("0"));
            }else{
                leijifootage = leijifootage.add(leiji.getFootage());
            }


            bodyRow = sheet.createRow(m);
            mergeCells(sheet, m, m, 2, 4);
            m++;
            createCell(wb, bodyRow, 1, "掘进二队", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            createCell(wb, bodyRow, 2, dimMiningFaceVO.getDrivageFaceName(), HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            createCell(wb, bodyRow, 6, dimMiningFaceVO.getDrivageFaceLength()==null?"":dimMiningFaceVO.getDrivageFaceLength()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            createCell(wb, bodyRow, 7, dimMiningFaceVO.getDrivageFaceLength().subtract(leijifootage)+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//剩余
            createCell(wb, bodyRow, 8, leijifootage==null?"":leijifootage+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//累计
            //根据工作面查询三班进尺
            BigDecimal todayleijifootage = new BigDecimal("0");
            List<ExecutionFootageOutputVO> outputVOS = detailFootageAndDevelopByData(dimMiningFaceVO.getDrivageFaceId(),beginDate);




            for (ExecutionFootageOutputVO footageOutputVO : outputVOS) {
                t++;
                todayleijifootage = todayleijifootage.add(footageOutputVO.getFootage());

                BigDecimal footage = footageOutputVO.getFootage();

                if (footageOutputVO.getShiftId().equals("0298c8a9d0639d715a0925f7b1ec2f55")) {
                    createCell(wb, bodyRow, 9,footage ==null?"":footage + "", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3"); // 早班进尺
                    morningTotal = morningTotal.add(footage);
                } else if (footageOutputVO.getShiftId().equals("0e0220e4af825d70d0932cc4504cd80d")) {
                    log.info("bodyRow="+bodyRow+"footage");
                    createCell(wb, bodyRow, 10,footage ==null?"":footage + "", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3"); // 中班进尺
                         afternoonTotal = afternoonTotal.add(footage);
                } else if (footageOutputVO.getShiftId().equals("70b1dacd7bf4db32cd37c1322a290005")){
                    createCell(wb, bodyRow, 11,footage ==null?"":footage + "", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3"); // 晚班进尺
                    nightTotal = nightTotal.add(footage);
                }
            }
            if(outputVOS.size()==0){
                createCell(wb, bodyRow, 9, "", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
                createCell(wb, bodyRow, 10,"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
                createCell(wb, bodyRow, 11, "", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            }
            createCell(wb, bodyRow, 12, todayleijifootage ==null?"":todayleijifootage+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//日累计

            Date[] dateRange = DateUtils.getDateRange(null, month);
            Date[] yearsdateRange = DateUtils.getDateRange(years, null);
            String s = DateUtils.parseDateToStr("yyyy-MM-dd", dateRange[0]);
            String y = DateUtils.parseDateToStr("yyyy-MM-dd", yearsdateRange[0]);
            //查询月累计进尺
            ExecutionFootageOutputVO footageOutputVO = executionFootageOutputMapper.selectPlanOutPutByFaceIdAndDate(dimMiningFaceVO.getDrivageFaceId(), s, beginDate);
            createCell(wb, bodyRow, 13, footageOutputVO==null?"":footageOutputVO.getFootage()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//月累计
            createCell(wb, bodyRow, 14, leijifootage ==null?"":leijifootage+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//累计
            ExecutionFootageOutputVO yuefootage = executionFootageOutputMapper.selectPlanOutPutByFaceIdAndDate(null, s, beginDate);
            ExecutionFootageOutputVO nianfootage = executionFootageOutputMapper.selectPlanOutPutByFaceIdAndDate(null, y, beginDate);


            createCell(wb, headLast1, 13, yuefootage==null?"":yuefootage.getFootage()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//月合计
            createCell(wb, headLast1, 14, nianfootage==null?"":nianfootage.getFootage()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//年合计
            List<ExecutionFootageOutputVO> rioutput = detailFootageAndDevelopByData(null,beginDate);
            BigDecimal totalFootage = rioutput.stream()
                    .map(ExecutionFootageOutputVO::getFootage)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            createCell(wb, headLast1, 12,totalFootage ==null?"":totalFootage+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//日合计

        }

        createCell(wb, headLast1, 8, "", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
        createCell(wb, headLast1, 9, morningTotal ==null?"":morningTotal+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//早合计
        createCell(wb, headLast1, 10,afternoonTotal ==null?"":afternoonTotal+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//中合计
        createCell(wb, headLast1, 11,nightTotal ==null?"":nightTotal+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//晚合计
        createCell(wb, headLast, 9,"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//晚合计
        createCell(wb, headLast, 10,"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//晚合计
        createCell(wb, headLast, 11,"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//晚合计
        m1 =555;
        for (DimMiningFaceVO dimMiningFaceVO : dimMiningFaceVOS) {
            bodyRow = sheet.createRow(rows + 3 + i);

            //根据工作面id获取进尺，获取当日进尺，获取月计划
            CooperativeMiningFacReq cooperativeMiningFacReq =new CooperativeMiningFacReq();
            cooperativeMiningFacReq.setMineCode(dimMiningFaceVO.getMineCode());
            cooperativeMiningFacReq.setId(dimMiningFaceVO.getMiningFaceId());
            log.info(cooperativeMiningFacReq.getId()+"回采工作面ID");
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            // 将 String 转换为 LocalDate
            LocalDate date = LocalDate.parse(beginDate, formatter);
            cooperativeMiningFacReq.setDate(date);

            CooperativeMiningFacVo cooperativeMiningFacVo = cooperativeMiningFacService.selectData(cooperativeMiningFacReq);

            BigDecimal months = planMiningMapper.planMonth(dimMiningFaceVO.getMiningFaceId(), dimMiningFaceVO.getMineCode(),beginDate);
            BigDecimal year = planMiningMapper.planYear(dimMiningFaceVO.getMiningFaceId(), dimMiningFaceVO.getMineCode(),beginDate);
            createCell(wb, bodyRow, 1, "综采二队", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            createCell(wb, bodyRow, 2, dimMiningFaceVO.getMiningFaceName(), HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            createCell(wb, bodyRow, 3,dimMiningFaceVO.getMiningFaceLength() ==null?"":dimMiningFaceVO.getMiningFaceLength()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");//可采走向长度
            //已采长度
            createCell(wb, bodyRow, 4, cooperativeMiningFacVo.getCurrentlyMineds() ==null?"":cooperativeMiningFacVo.getCurrentlyMineds()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            //剩余长度
            createCell(wb, bodyRow, 5, cooperativeMiningFacVo.getOverslength() ==null?"":cooperativeMiningFacVo.getOverslength()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            //推采进度
            createCell(wb, bodyRow, 6,cooperativeMiningFacVo.getNowFootage()  ==null?"":cooperativeMiningFacVo.getNowFootage()+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3");
            createCell(wb, bodyRow, 7, months==null?"":months+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3"); //月计划
            createCell(wb, bodyRow, 8,year ==null?"":year+"", HSSFColor.HSSFColorPredefined.GREY_25_PERCENT, "3"); //年计划
            i++; // 递增 i

            if(m1==555){
                ProduceStasticVO produceStasticVO = iStatisticService.produceForBigScreen(null, mineCode);
                if (produceStasticVO!=null){
                    log.info("produceStasticVO");
                    createCell(wb,bodyRow,9,produceStasticVO.getProduceDay()==null?"":produceStasticVO.getProduceDay()+"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"3");
                    createCell(wb,bodyRow,11,produceStasticVO.getProduceMonth()==null?"":produceStasticVO.getProduceMonth()+"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"3");
                    createCell(wb,bodyRow,13,produceStasticVO.getProduceYear()==null?"":produceStasticVO.getProduceYear()+"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"3");
                    log.info("produceStasticVO结束");
                    m1=0;
                }
            }
        }

        createTitle(wb,titleRow,"砚北煤矿安全生产信息统计表");

        createTitle(wb,head,beginDate);
        createCell(wb,head2,0,"原煤产量\r销量\r入选量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"1");
        createCell(wb,head2,1,"区队",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
//        createCell(wb,head3,1,"综采一队",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,2,"工作面",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,3,"设计回\n" + "采长度",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,4,"累计回\n" + "采长度",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,5,"剩余可\n" + "采长度",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,6,"当日推\n" + "采进度",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,7,"月计划",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,8,"年计划",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head2,9,"全矿原煤产量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head3,9,"日",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head3,11,"月",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,head3,13,"年",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf5,1,"掘进煤",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf5,1,"掘进煤",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf5,7,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf5,8,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf4,1,"矸石",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf4,8,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf3,1,"合计",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf3,7,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf3,8,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf2,1,"原煤入洗量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf2,8,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf1,1,"商品煤销量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headf1,8,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,0,"掘进进尺",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"1");
        createCell(wb,headz1,1,"区队",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,2,"工作面",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,5,"类型",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,6,"设\r计\n" + "工程量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,7,"剩\r余\n" + "工程量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,8,"已掘进\n工程量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,9,"每班进尺（排）",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz1,12,"进尺统计（米）",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz2,9,"早",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz2,10,"中",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz2,11,"夜",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz2,12,"日",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz2,13,"月",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headz2,14,"累计量",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headLast,1,"合\r\r计",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headLast,12,"日",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headLast,13,"月",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headLast,14,"年",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        createCell(wb,headLast,8,"",HSSFColor.HSSFColorPredefined.GREY_25_PERCENT,"2");
        mergeCells(sheet, 2, 3+dimMiningFaceVOS.size()+5, 0, 0);
        mergeCells(sheet, 3, 3, 9, 10);
        mergeCells(sheet, 3, 3, 11, 12);
        mergeCells(sheet, 3, 3, 13, 14);


        for (int j = 4; j <= 3+dimMiningFaceVOS.size()+5; j++) {
            mergeCells(sheet, j, j, 11, 12);
            mergeCells(sheet, j, j, 13, 14);
            mergeCells(sheet, j, j, 9, 10);
        }
        mergeCells(sheet, 0, 0, 0, 14);
        mergeCells(sheet, 1, 1, 0, 14);
        mergeCells(sheet, 2, 3, 1, 1);
        mergeCells(sheet, 2, 3, 2, 2);
        mergeCells(sheet, 2, 3, 3, 3);
        mergeCells(sheet, 2, 3, 4, 4);
        mergeCells(sheet, 2, 3, 5, 5);
        mergeCells(sheet, 2, 3, 7, 7);
        mergeCells(sheet, 2, 3, 8, 8);
        mergeCells(sheet, 2, 3, 6, 6);
        mergeCells(sheet, 2, 2, 9, 14);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+1, 3+ dimMiningFaceVOS.size()+1, 1, 6);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+2, 3+ dimMiningFaceVOS.size()+2, 1, 6);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+3, 3+ dimMiningFaceVOS.size()+3, 1, 6);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+4, 3+ dimMiningFaceVOS.size()+4, 1, 6);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5, 3+ dimMiningFaceVOS.size()+5, 1, 6);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 1+3+ dimMiningFaceVOS.size()+5+drivageFaceVOS.size()+3, 0, 0);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+2, 1, 1);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+2, 2, 4);


        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+2, 5, 5);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+2, 6, 6);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+2, 7, 7);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+2, 8, 8);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+1, 9, 11);
        mergeCells(sheet, 3+ dimMiningFaceVOS.size()+5+1, 3+ dimMiningFaceVOS.size()+5+1, 12, 14);
        mergeCells(sheet, 1+3+ dimMiningFaceVOS.size()+5+2+drivageFaceVOS.size(), 1+3+ dimMiningFaceVOS.size()+5+2+drivageFaceVOS.size()+1, 1, 7);

        try {
            String fileName = URLEncoder.encode("砚北煤矿安全生产信息统计表","UTF-8");
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.setHeader("Content-Disposition","attachment;filename="+fileName+".xls");
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
            wb.close();
        }catch (Exception e){

        }
    }

    @Override
    public List<MiningstasticVo> productionStatisticsList(String beginDate, String mineCode) {

        return null;
    }

    private void mergeCells(HSSFSheet sheet, int firstRow, int lastRow, int firstCol, int lastCol) {
        sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
        // 设置合并单元格的边框样式
        RegionUtil.setBorderTop(BorderStyle.THIN, new CellRangeAddress(firstRow, lastRow, firstCol, lastCol), sheet);
        RegionUtil.setBorderBottom(BorderStyle.THIN, new CellRangeAddress(firstRow, lastRow, firstCol, lastCol), sheet);
        RegionUtil.setBorderLeft(BorderStyle.THIN, new CellRangeAddress(firstRow, lastRow, firstCol, lastCol), sheet);
        RegionUtil.setBorderRight(BorderStyle.THIN, new CellRangeAddress(firstRow, lastRow, firstCol, lastCol), sheet);
    }

}
